package D12_9z.xml练习题.xml解析_3;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        ArrayList<Student> arr = new ArrayList<>();
        SAXReader sax = new SAXReader();
        Document read = sax.read("src/Y2019/M12_/D12_9/xml练习题/xml解析_3/student.xml");
        Element root = read.getRootElement();
        List<Element> student = root.elements("student");
        for (Element ele : student) {
            Student s1 = new Student();
            s1.setStuNo(ele.attributeValue("stuNo"));
            s1.setName(ele.elementText("name"));
            s1.setAge(Integer.parseInt(ele.elementText("age")));
            s1.setSex(ele.elementText("sex"));
            s1.setScore(Integer.parseInt(ele.elementText("score")));
            arr.add(s1);
        }
        System.out.println(arr);
    }
}
